<template>
    <div>
        <div class="search-content">
            <el-form ref="searchForm" :inline="true" :model="searchContent">
                <el-form-item label="话术ID：" prop="supplier_product_id">
                    <el-input
                        class="search-content-input"
                        v-model="searchContent.supplier_product_id"
                        placeholder="话术ID"
                    ></el-input>
                </el-form-item>
                <el-form-item label="店铺ID：" prop="store_id">
                    <el-input
                        class="search-content-input"
                        v-model="searchContent.store_id"
                        placeholder="店铺ID"
                    ></el-input>
                </el-form-item>
                <el-form-item label="话术名称：" prop="productName">
                    <el-input
                        class="search-content-input"
                        v-model="searchContent.productName"
                        placeholder="话术名称"
                    ></el-input>
                </el-form-item>
				<el-form-item label="店铺名称：" prop="storeName">
                    <el-input
                        class="search-content-input"
                        v-model="searchContent.storeName"
                        placeholder="店铺名称"
                    ></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="search">搜索</el-button>
                    <el-button type="primary" @click="resetSearchData">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="search-list">
            <el-table :data="goodsList" border :height="oHeight" :fit="true">
                <!-- <el-table-column align="center" type="selection" width="55"></el-table-column> -->
                <el-table-column align="center" prop="id" label="ID" min-width="60"></el-table-column>
				<el-table-column align="center" prop="store_id" label="店铺ID" min-width="60"></el-table-column>
                <el-table-column align="center" prop="store_name" label="店铺名称" min-width="130"></el-table-column>
                <el-table-column align="center" prop="supplier_product_id" label="供应商话术ID" min-width="110"></el-table-column>
                <el-table-column align="center" prop="product_description" label="话术名称" min-width="170"></el-table-column>
                <el-table-column align="center" prop="application_scenarios" label="应用场景" min-width="70"></el-table-column>
                <el-table-column align="center" prop="scenarios_sub_category" label="二级场景" min-width="150"></el-table-column>
                <el-table-column align="center" prop="call_line_name" label="线路名称" min-width="120" #default="{row}">
                    <el-tooltip class="item" effect="dark" :content="`${row.call_line_number}、${row.call_line_index}、${row.call_remark}`" placement="top-start">
                        <span>{{row.call_line_name}}</span>
                    </el-tooltip>
                </el-table-column>
                <el-table-column align="center" prop="second_quality" label="开启T" min-width="70">
                    <template slot-scope="scope">
                        <div  slot="reference" type="text" >{{scope.row.second_quality=='0'?'否':'是'}}</div>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="service_suppliers_name" label="供应商" min-width="120"></el-table-column>
                <el-table-column
                    fixed="right"
                    align="center"
                    prop="isInitiative"
                    label="操作"
                    min-width="120"
                >
                    <template #default="{row}">
                        <el-button type="text" @click="showContent('edit', row)">编辑</el-button>
                        <el-button type="text" @click="copyLink(row)">复制</el-button>
                        <el-button type="text" @click="delContent(row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="bottom">
                <div class="btn-group">
                    <el-button type="primary" class="btn-bottom" @click="showContent('add')">新增</el-button>
                    <!-- <el-button type="primary" class="btn-bottom" @click="expertData">导出检索数据</el-button> -->
                </div>
                <!--分页部分-->
                <div class="paginationOne">
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="searchContent.currentPage"
                        :page-sizes="[10, 20, 50, 100]"
                        :page-size="searchContent.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total*1"
                    ></el-pagination>
                </div>
            </div>
        </div>
        <edit-drawer ref="editDrawer"></edit-drawer>
    </div>
</template>
<script>
import { resize } from "@/common/js/height.js";
import editDrawer from './show-edit-drawer';
import { dateFormatter, objScreen } from "@/common/js/util";
export default {
    components: { editDrawer },
    data() {
        return {
            goodsList: [],
            oHeight: 800,
            searchContent: {
                currentPage: 1,
                pageSize: localStorage.getItem('pageSize') * 1 || 10,
                supplier_product_id: '',
                store_id: '',
                productName: '',
                storeName: ''
            },
            searchObj: {},
            total: 0,
        };
    },
    created() {
        this.getListData();
    },
    methods: {
        showContent(type, row) {
            if (type === 'add') {
                this.$refs.editDrawer.show_dialog_fn('add', row)
            } else {
                this.$refs.editDrawer.show_dialog_fn('edit', row)
            }

		},
		delContent({id}){
			if(!confirm('确定删除吗?')){
				return
			}
			this.$http.post("/admin/dataService/index.php?act=merchantSet&op=delMerchantWord", {id}).then(res => {
                if (res.code === 1) {
					this.$message.success(res.msg);
					this.getListData();
                } else if (res) {
                    this.$message.error(res.msg);
                }
            }).catch(err => {
                this.$message.error(err);
            })
		},
        changeStatus(row, status) {
            this.$http.post("/admin/dataService/index.php?act=merchantSet&op=updateContractStatus", {
                ID: row.ID,
                status
            }).then(res => {
                if (res.code === 1) {
					row.ContractStatus = status;
					this.$message.success(res.msg);
                } else if (res) {
                    this.$message.error(res.msg);
                }
            }).catch(err => {
                this.$message.error(err);
            })
        },
        getListData() {
            var data = this.searchObj;
            data.currentPage = this.searchContent.currentPage;
            data.eachNum = this.searchContent.pageSize;
            this.$http.post('/admin/dataService/index.php?act=merchantSet&op=merchantWordList', data).then((res) => {
                if (res.code === 1) {
                    this.total = res.data.total;
                    this.goodsList = res.data.list;
                    // this._message('success', res.msg);
                    // this.getListData();
                } else {
                    this.total = 0;
                    this.goodsList = [];
                    this._message('error', res.msg);
                }
            }).catch(err => {
                this._message('error', err);
            })
        },
        search() {
			this.searchContent.currentPage = 1;
            let { productName, store_id, storeName, supplier_product_id } = this.searchContent;
            this.searchObj = objScreen({
				productName, 
				store_id, 
				storeName, 
				supplier_product_id
            })
            this.getListData();
        },
        resetSearchData() {
            this.$refs['searchForm'].resetFields();
            this.searchObj = {};
            this.getListData();            
        },
        handleSizeChange(pageSize) {
            localStorage.setItem('pageSize', pageSize);
            this.searchContent.pageSize = pageSize;
            this.searchContent.currentPage = 1;
            this.getListData();
        },
        handleCurrentChange(page) {
            this.searchContent.currentPage = page;
            this.getListData();
        },
        copyLink(row){
            console.log(row,'row');
            this.$http.post('/admin/dataService/index.php?act=merchantSet&op=copyMerchantWord',{id:row.id}).then(res=>{
                if(res.code == 1){
                    this.$message.success(res.msg);
                    this.getListData();
                }else{
                    this.$message.waring(res.msg);
                }
            })
        }
    },
    mounted() {
        resize(this)
    },
};
</script>
<style lang="scss" scoped>
.bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.search-content-input {
    width: 200px;
}
</style>